home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / macabuse / imlib / include / image.hpp < prev    next >
C/C++ Source or Header  |  1997-05-20  |  7KB  |  186 lines

  1. #ifndef _IMGAE_HPP_
  2. #define _IMGAE_HPP_
  3. #include <stdlib.h>
  4. #include "linked.hpp"
  5. #include "palette.hpp"
  6. #include "system.h"
  7. #include "specs.hpp"
  8. #include "dprint.hpp"
  9. #define MAX_DIRTY 200
  10. #define Inew(pointer,type); { make_block(sizeof(type)); pointer=new type; }
  11.  
  12. extern char  *imerr_messages[];  // correspond to imERRORS
  13. #define imREAD_ERROR            1
  14. #define imINCORRECT_FILETYPE   2
  15. #define imFILE_CORRUPTED       3
  16. #define imFILE_NOT_FOUND       4
  17. #define imMEMORY_ERROR         5
  18. #define imNOT_SUPPORTED        6
  19. #define imWRITE_ERROR          7
  20. #define imMAX_ERROR            7
  21.  
  22. short current_error();
  23. void clear_errors();
  24. void set_error(short x);
  25. short last_error();
  26. void make_block(size_t size);
  27. void image_init();
  28. void image_uninit();
  29. extern linked_list image_list;
  30.  
  31.  
  32. class filter;
  33.  
  34.  
  35. class dirty_rect : public linked_node
  36. {
  37. public :
  38.   short dx1,dy1,dx2,dy2;
  39.   dirty_rect(short x1, short y1, short x2, short y2)
  40.   { dx1=x1; dy1=y1; dx2=x2; dy2=y2; 
  41.     if (x2<x1 || y2<y1) 
  42.       dprintf("add incorrect dirty\n");
  43.   }
  44.   virtual short compare(void *n1, short field)
  45.   { return ((dirty_rect *)n1)->dy1>dy1; }
  46. } ;
  47.  
  48. class image_descriptor
  49. {
  50.   short l,h;
  51.   short clipx1, clipy1, clipx2, clipy2;
  52. public :  
  53.   unsigned char keep_dirt,
  54.             static_mem;      // if this flag is set then don't free memory on exit
  55.   
  56.   linked_list dirties;
  57.   void *extended_descriptor;              // type depends on current system
  58.  
  59.   image_descriptor(short length, short height,
  60.           int keep_dirties=1, int static_memory=0);
  61.   short bound_x1(short x1)  { return x1<clipx1 ? clipx1 : x1; }
  62.   short bound_y1(short y1)  { return y1<clipy1 ? clipy1 : y1; }
  63.   short bound_x2(short x2)  { return x2>clipx2 ? clipx2 : x2; }
  64.   short bound_y2(short y2)  { return y2>clipy2 ? clipy2 : y2; }
  65.   short x1_clip() { return clipx1; }
  66.   short y1_clip() { return clipy1; }
  67.   short x2_clip() { return clipx2; }
  68.   short y2_clip() { return clipy2; }
  69.   void dirty_area(short x1, short y1, short x2, short y2) { ;}
  70.   void clean_area(short x1, short y1, short x2, short y2) { ; }
  71.   void clear_dirties();
  72.   short get_dirty_area(short &x1, short &y1, short &x2, short &y2) { return 0; }
  73.   void get_clip(short &x1, short &y1, short &x2, short &y2)
  74.     { x1=clipx1; y1=clipy1; x2=clipx2; y2=clipy2; }
  75.   void set_clip(short x1, short y1, short x2, short y2)
  76.     { if (x2<x1) x2=x1;
  77.       if (y2<y1) y2=y1;
  78.       if (x1<0) clipx1=0; else clipx1=x1;
  79.       if (y1<0) clipy1=0; else clipy1=y1;
  80.       if (x2>=l) clipx2=l-1; else clipx2=x2;
  81.       if (y2>=h) clipy2=h-1; else clipy2=y2;
  82.     }
  83.   void reduce_dirties();
  84.   void add_dirty(int x1, int y1, int x2, int y2);
  85.   void delete_dirty(int x1, int y1, int x2, int y2);
  86.   void resize(short length, short height)
  87.    { l=length; h=height; clipx1=0; clipy1=0; clipx2=l-1; clipy2=h-1; }
  88. } ;
  89.  
  90. class image : public linked_node
  91.   void make_page(short width, short height, unsigned char *page_buffer);
  92.   void delete_page();
  93. public :
  94.   short w,h;
  95.   unsigned char *data;
  96.     void HackW(short _w) { w = _w; }
  97.     void HackH(short _h) { h = _h; }
  98.  
  99.  
  100.  
  101.   image_descriptor *special;
  102.   image(spec_entry *e, bFILE *fp);
  103.   image(bFILE *fp);
  104.   image(short width, short height,                 // required
  105.     unsigned char *page_buffer=NULL,
  106.     short create_descriptor=0);        // 0=no, 1=yes, 2=yes & keep dirties
  107.   unsigned char  pixel              (short x, short y);
  108.   void           putpixel           (short x, short y, char color);
  109.   unsigned char *scan_line          (short y) { return data+y*w; }
  110.   unsigned char *next_line          (short lasty, unsigned char *last_scan) 
  111.                                     { return last_scan+w; }          
  112.   long           total_pixels       (unsigned char background=0);
  113.   image         *copy               ();    // makes a copy of an image
  114.   void           clear              (short color=-1);  // -1 is background color
  115.   void           to_24bit           (palette &pal);
  116.   short          width              () { return (short)w; }
  117.   short          height             () { return (short)h; }
  118.   void           scroll             (short x1, short y1, short x2, short y2, short xd, short yd);
  119.   void           fill_image         (image *screen, short x1, short y1, short x2, short y2, 
  120.                      short allign=1);
  121.   void           put_image          (image *screen, short x, short y, char transparent=0);
  122.   void           put_part           (image *screen, short x, short y, short x1, short y1, 
  123.                      short x2, short y2, char transparent=0);
  124.   void           put_part_xrev      (image *screen, short x, short y, short x1, short y1, 
  125.                      short x2, short y2, char transparent=0);
  126.   void           put_part_masked    (image *screen, image *mask, short x, short y, 
  127.                      short maskx, short masky, short x1, short y1, short x2, short y2);
  128.   image         *copy_part_dithered (short x1, short y1, short x2, short y2);
  129.   void           bar                (short x1, short y1, short x2, short y2, unsigned char color);
  130.   void           xor_bar            (short x1, short y1, short x2, short y2, unsigned char color);
  131.   void              wiget_bar          (short x1, short y1, short x2, short y2, 
  132.                      unsigned char light, unsigned char med, unsigned char dark);
  133.   void           line               (short x1, short y1, short x2, short y2, unsigned char color);
  134.   void           rectangle          (short x1, short y1, short x2, short y2, unsigned char color);
  135.   void           burn_led           (short x, short y, long num, short color, short scale=1);
  136.   void           set_clip           (short x1, short y1, short x2, short y2);
  137.   void           get_clip           (short &x1,short &y1,short &x2,short &y2);
  138.   void           in_clip            (short x1, short y1, short x2, short y2);
  139.  
  140.   void           dirt_off           () { if (special && special->keep_dirt) special->keep_dirt=0; }
  141.   void           dirt_on            () { if (special) special->keep_dirt=1; }
  142.  
  143.   void           add_dirty          (int x1, int y1, int x2, int y2) 
  144.                                     { if (special) special->add_dirty(x1,y1,x2,y2); }
  145.   void           delete_dirty       (int x1, int y1, int x2, int y2) 
  146.                                     { if (special) special->delete_dirty(x1,y1,x2,y2); }
  147.   void           clear_dirties      () { if (special) special->clear_dirties(); }
  148.   void           dither             (palette *pal); // use a b&w palette!
  149.   void           resize             (short new_width, short new_height);
  150.   void           change_size        (short new_width, short new_height, unsigned char *page=NULL);
  151.   void           flood_fill         (short x, short y, unsigned char color);
  152.   image         *create_smooth      (short smoothness=1); // 0 no smoothness
  153.   void           unpack_scanline    (short line, char bitsperpixel=1);
  154.   unsigned char  brightest_color    (palette *pal);
  155.   void           flip_x              ();
  156.   void           flip_y             ();
  157.   void           make_color         (unsigned char color);
  158.   unsigned char  darkest_color      (palette *pal, short noblack=0);
  159.  
  160.   ~image();
  161. } ;
  162.  
  163.  
  164. class image_controller
  165. {
  166. public :
  167.   image_controller() { image_init(); }
  168.   ~image_controller()
  169.   { 
  170.      image_uninit(); 
  171.   }
  172. } ;
  173.  
  174.  
  175.  
  176. #endif
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.